from turbogears import expose, identity, validate, validators, redirect, controllers
from onlineapidoc.model import User, Space, Template, Page, space_status_codes, SPACE_STATUS_UNAVAILABLE

class DashboardController(controllers.Controller):
    @expose(template="onlineapidoc.templates.dashboard.index")
    def index(self):
        all_spaces = Space.select(Space.q.status != SPACE_STATUS_UNAVAILABLE, orderBy='name')
        templates = Template.select(orderBy='name')
        last_updated = Page.select(orderBy='-last_edit_time')[:50]
        
        return dict(active_section='dashboard',
                    spaces=all_spaces, 
                    space_status_codes=space_status_codes,
                    last_updated=last_updated)
    
